package ee.az.test.lighting;

/**
 * @author Artur Zinatullin (artur.zinatullin@gmail.com) 2010
 */
public class Line {
	private Point[] points;
	
	public Line(int length) {
		points = new Point[length];
	}
	
	public Point[] getPoints() {
		return points;
	}
	public int getLength() {
		return points.length;
	}
	
	public class Point {
		private final int x, y;
		private final Spot spot;
		public Point(int x, int y, Spot spot) {
			this.x = x; this.y = y;
			this.spot = spot;
		}
		public int getX() {
			return x;
		}
		public int getY() {
			return y;
		}
		public Spot getSpot() {
			return spot;
		}
	}
	
	public void append(Line line) {
		Point[] old = points;
		points = new Point[old.length + line.getLength()];
		for (int i=0; i<old.length; i++) {
			points[i] = old[i];
		}
		for (int i=old.length; i<points.length; i++) {
			points[i] = line.getPoints()[i-old.length];
		}
	}
	
	public void copy(Line line) {
		copy(0, line);
	}
	public void copy(int startIndex, Line line) {
		for (int i=0; i<line.getLength(); i++) {
			points[i+startIndex] = line.getPoints()[i];
		}
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<getLength(); i++) {
			sb.append(points[i].getSpot());
		}
		return sb.toString();
	}
}
